$('#reset').click(function(){
    $('input').val('');
})


jQuery.Huitab = function (tabBar, tabCon, class_name, tabEvent, i) {
    var $tab_menu = $(tabBar);
    // 初始化操作
    $tab_menu.removeClass(class_name);
    $(tabBar).eq(i).addClass(class_name);
    $(tabCon).hide();
    $(tabCon).eq(i).show();
    $tab_menu.bind(tabEvent, function () {
        $tab_menu.removeClass(class_name);
        $(this).addClass(class_name);
        var index = $tab_menu.index(this);
        $(tabCon).hide();
        $(tabCon).eq(index).show();
    });
}

$(function () {
    $.Huitab("#tab_goods .tabBar span", "#tab_goods .tabCon", "current", "click", "0")
});
// #tab_demo 父级id
// #tab_demo .tabBar span 控制条
// #tab_demo .tabCon 内容区
// click 事件 点击切换，可以换成mousemove 移动鼠标切换
// 1	默认第2个tab为当前状态（从0开始）

$(function () {
    $('.skin-minimal input').iCheck({
        checkboxClass: 'icheckbox-blue',
        radioClass: 'iradio-blue',
        increaseArea: '20%'
    })
});

var id = getQueryString('sign_id');
var arr1 = new Array(); //1级分类ID
var arr2 = new Array(); //2级分类ID
var arr3 = new Array(); //3级分类ID
var applcationRange; //适用范围 0:全部分类 1:指定分类 2:指定场景
var arr4 = new Array();//根据二级查询的一级分类ID 数组
var arr5 = new Array();//根据三级查询的二级分类ID 数组
$.ajax({
    url: root.cooperation.selectSencondSign,
    cache: false,  //禁用缓存
    type: "POST",
    dataType:'json',
    async:false,
    // contentType: "application/json",
    data: {
        "sign_id":id
    },
    success: function (data) {
        console.log(data);
        //状态
        if (data.potal_sign.state == 10) {
            $('#state').html('待处理');
            $("#detail_statue").show();
        } else if (data.potal_sign.state == 20) {
            $('#state').html('处理中');
            $("#detail_statue").show();
        } else if (data.potal_sign.state == 30) {
            $('#state').html('已处理');
            $("#detail_statue").hide();
        }



        //描述
        $('#type').html(data.potal_sign.type);
        if(data.potal_sign.type == 2){
            $('#type').html('供应商合作');
        }else if (data.potal_sign.type == 3) {
            $('#type').html('采购商合作');

        } else if (data.potal_sign.type == 4) {
            $('#type').html('AIC合作');

        }
        $('#company_name').html(data.potal_sign.company_name);
        $('#receiver_province_name').html(data.potal_sign.receiver_province_name+'&nbsp;&nbsp;'+data.potal_sign.receiver_city_name+'&nbsp;&nbsp;'+data.potal_sign.receiver_area_name+'&nbsp;&nbsp;'+data.potal_sign.street_name);
        $('#linkman').html(data.potal_sign.linkman);
        $('#linkman_post').html(data.potal_sign.linkman_post);
        $('#linkman_phone').html(data.potal_sign.linkman_phone);
        $('#age').html(data.potal_sign.age);
        $('#sex').html(data.potal_sign.sex);
        $('#operating_years').html(data.potal_sign.operating_years);
        $('#number_of_employees').html(data.potal_sign.number_of_employees);
        $('#management_mode').html(data.potal_sign.management_mode);
        $('#annual_turnover').html(data.potal_sign.annual_turnover);
        $('#store_address').html(data.potal_sign.store_address);
        $('#operating_area').html(data.potal_sign.operating_area);
        $('#cooperative_store').html(data.potal_sign.cooperative_store);
        $('#cooperation_budget').html(data.potal_sign.cooperation_budget);
        $('#linkman_landline').html(data.potal_sign.linkman_landline);
        $('#mail').html(data.potal_sign.mail);
        if (data.potal_sign.model_config == 1) {

            $('#model_config').html('国有');

        } else if (data.potal_sign.model_config == 2) {

            $('#model_config').html('集体');

        } else if (data.potal_sign.model_config == 3) {

            $('#model_config').html('私营');

        }else if (data.potal_sign.model_config == 4) {

            $('#model_config').html('三资');

        }else if (data.potal_sign.model_config == 5) {

            $('#model_config').html('个体');

        }else if (data.potal_sign.model_config == 6) {

            $('#model_config').html('其他');

        }else if (data.potal_sign.model_config == 7) {

            $('#model_config').html('生产商');

        }else if (data.potal_sign.model_config == 8) {

            $('#model_config').html('总代理');

        }else if (data.potal_sign.model_config == 9) {

            $('#model_config').html('经销商');

        }else if (data.potal_sign.model_config == 10) {

            $('#model_config').html('二级经销商');

        }else if (data.potal_sign.model_config == 11) {

            $('#model_config').html('其他');

        }
        $('#sign_brand').html(data.potal_sign.sign_brand);
        $('#expected_sales').html(data.potal_sign.expected_sales);


        /*$('#main_brand').html(data.potal_sign.main_brand);*/
        $('#message').html(data.potal_sign.message);
        var handStr = '';

        if(data.potal_handle && data.potal_handle.length>0){
            $.each(data.potal_handle,function(k,v){
                console.log(k);
                console.log(v);
                handStr+='<tr class="biaoge1">' +
                    '<td class="biaoge1-1"><span id="handle_man">'+v.handle_man+'</span></td>' +
                    '<td class="biaoge1-2"><span id="handle_results">'+v.handle_results+'</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">'+formatDate(v.create_time)+'</span></td>'+
                    '</tr>';
            });
            $("#tableId").find(".biaogeempty").remove();
            $("#tableId").find("tbody").append($(handStr));
        }

        $('#handle_results').html(data.potal_handle.handle_results);
        $('#create_time').html(data.potal_handle.create_time);
        $("#detail_statue").html("<span class=\"list powerButton 215\" id='"+data.potal_sign.id+"' onclick='dealmodaldemo("+data.potal_sign.id+")'>处理</span>")




    },
    error: function () {
        $.Huimodalalert('失败！');
    }
});
$('#putout').attr('href',root.couponInter.coupon_exportProductExcel+id);

var index=0;
function dealmodaldemo(id) {
    var popEle = $('#chuliPop');
    var curInd = layer.confirm('<textarea id="handle_info" style="width:200px;height:100px;resize: none;" maxlength="200" placeholder="请填写处理结果"></textarea>', {title:'提示',btn: ['保存', '完结']}, function(index){

        var inv = $("#handle_info").val();
        finish1(id,curInd)
        layer.close(curInd);
    },function(){
        finish2(id,curInd)
        var inv = $("#handle_info").val();
        layer.close(curInd);

    });
}

// var loginData = web.readCookie("loginData");
function finish1(id,val){
    var target = document.getElementById(''+id+'');
    var reason=$('#reason'+id+'').val();

   /* //覆盖旧信息

    $("#handle_results").html(handle_info);
    var myTime = new Date().getTime();
    var time = format(myTime);
    $("#create_time").html(time);*/

    var handle_info=$('#handle_info').val();
    console.log($('#handle_info').val());
    /*console.log(time);

    console.log(target.parentElement.previousElementSibling)*/
    if(reason!=''){
        var handleName = JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name;
        $.ajax({
            contentType: "application/json;charset=UTF-8",
            url: root.cooperation.update,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            // contentType: "application/json",
            data: JSON.stringify({
                "sign_id":id,
                "state":20,
                "handle_man":handleName,
                "handle_results":$('#handle_info').val()


            }),
            success: function (data) {

                if(data.code==0){
                    //重新渲染请求数据
                    window.parent.searchList(0);
                    target.onclick = null;
                    target.setAttribute("onclick", 'dealmodaldemo('+id+')')
                    target.parentElement.previousElementSibling.innerHTML='处理中'

                    var myTime = new Date().getTime();
                    var time = format(myTime);
                    $(".tableTR").after('<tr class="biaoge1 biaogeempty"><td class="biaoge1-1"><span id="handle_man">'+handleName+'</span></td><td class="biaoge1-2"><span id="handle_results">'+handle_info+'</span></td><td class="biaoge1-3"><span id="create_time">'+time+'</span></td></tr>')
                }

            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        })
    }
    else{
        $.Huimodalalert('处理结果不能为空！',2000);
    };
    layer.close(index);





}
//第二个
function finish2(id,val){
    var target = document.getElementById(''+id+'');
    var handle_info=$('#handle_info').val();
   /*
    target.parentElement.parentElement.parentElement.previousElementSibling.previousElementSibling.innerHTML=handle_info;
*/

    var reason=$('#reason'+id+'').val();
    // console.log(target.parentElement.parentElement.parentElement.previousElementSibling.previousElementSibling.previousElementSibling.previousElementSibling)
    if(reason!=''){
        var handleName = JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name;
        $.ajax({
            contentType: "application/json;charset=UTF-8",
            url: root.cooperation.update,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            // contentType: "application/json",
            data: JSON.stringify({
                "state":30,
                "sign_id":id,
                "handle_man":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                "handle_results":$('#handle_info').val()

            }),
            success: function (data) {
                if(data.code==0) {
                    window.parent.searchList(0);

                    console.log(data)
                    target.style.color = '#999';
                    target.onclick = null;
                    target.parentElement.previousElementSibling.innerHTML = '已处理'

                    var myTime = new Date().getTime();
                    var time = format(myTime);
                    $(".tableTR").after('<tr class="biaoge1 biaogeempty"><td class="biaoge1-1"><span id="handle_man">' + handleName + '</span></td><td class="biaoge1-2"><span id="handle_results">' + handle_info + '</span></td><td class="biaoge1-3"><span id="create_time">' + time + '</span></td></tr>')
                }
                },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        })}
    else{
        $.Huimodalalert('处理结果不能为空！',2000);
    };
    layer.close(index);
}

//时间转换
function add0(m){return m<10?'0'+m:m }
function formatDate(needTime)
{
    //needTime是整数，否则要parseInt转换
    var time = new Date(needTime);
    var y = time.getFullYear();
    var m = time.getMonth()+1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
}
